/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.engagesoft.cashflow.bean;

import com.engagesoft.cashflow.entidades.Documento;
import com.engagesoft.cashflow.entidades.MovimientoDocumento;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author rchajin
 */
@Stateless
public class MovimientoDocumentoFacade extends AbstractFacade<MovimientoDocumento> {
    @PersistenceContext(unitName = "com.engagesoft_CashFlow_war_1.0PU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public MovimientoDocumentoFacade() {
        super(MovimientoDocumento.class);
    }
    
    public List<MovimientoDocumento> encontrarPorIdDocumento(Documento doc) {
        List<MovimientoDocumento> movDoc = new ArrayList<>();
        
        try {
            Query q = em.createNamedQuery("MovimientoDocumento.findByIdDocumento").setParameter("idDocumento", doc);
            movDoc = (List<MovimientoDocumento>) q.getResultList();
        } catch (Exception ex) {
            ex.printStackTrace();
        }

        return movDoc;
    }     
    
}
